package com.lk.api.app;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.lk.api.R;
import com.lk.api.entity.Users;

/**
 * Created by lk on 2014/12/25.
 */
public class Save extends Activity {
    EditText editTextName, editTextPwd;
    Intent intent;
    DBOperation dbOperation;
    Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.s);
        editTextName = (EditText) findViewById(R.id.editTextName);
        editTextPwd = (EditText) findViewById(R.id.editTextPwd);
        dbOperation = new DBOperation(Save.this);
        dbOperation.openOrCreateDatabase();

        button = (Button) findViewById(R.id.buttonsave);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Users users = new Users();
                if (users != null && dbOperation != null) {
                    users.setNames(editTextName.getText().toString());
                    users.setPwd(editTextPwd.getText().toString());
                    dbOperation.insertData(users);
                    Toast.makeText(Save.this, "保存成功", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(Save.this, "保存失败", Toast.LENGTH_LONG).show();
                }
                finish();

            }
        });

//        intent = this.getIntent();
//        String receiveData;
//        if (intent != null) {
//            receiveData = intent.getExtras().getString("mPosition");
//            Log.d("receiveData", "" + receiveData);
//        }
    }
}
